#-*- encoding: utf-8 -*-

'''
Created on 2011-5-17

@author: wubotao
'''

import cx_Oracle

import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'


DATABASES = {
    'NAME': 'ORCL',
    'USER': 'GIILBSDB',
    'PASSWORD': '1',
    'HOST': '192.168.0.43',
    'PORT': '1521',
}

def fetch_data (sql): 
    try:
        dsn = cx_Oracle.makedsn(DATABASES['HOST'], DATABASES['PORT'], DATABASES['NAME'])
        conn = cx_Oracle.connect(DATABASES['USER'], DATABASES['PASSWORD'], dsn)
        try:
            cur = conn.cursor()
            cur.execute(sql)
            data = cur.fetchall() 
        finally:
            cur.close()
            conn.close()
    except Exception, e: 
        print 'Error:', e
        return

    return data

def send_data(sql):
    try:
        dsn = cx_Oracle.makedsn(DATABASES['HOST'], DATABASES['PORT'], DATABASES['NAME'])
        conn = cx_Oracle.connect(DATABASES['USER'], DATABASES['PASSWORD'], dsn)
        try:
            cur = conn.cursor()
            cur.execute(sql)
            conn.commit() 
        finally:
            cur.close()
            conn.close()
    except Exception, e: 
        print 'Error:', e


if __name__ == '__main__':
    sql = '''SELECT ID,ATTACH_ID,B_OBJID,B_SHMC,B_SHDZ,B_GDDH,B_YDDH,B_SSHY,B_XZB,B_YZB
            FROM LBS_USER_TRADESMAN WHERE ID = 666 '''
    data = fetch_data(sql)
    
    print data[0][3]
